package com.syni.mdd.yhd.common.all.dto.requestDto.groupBuy;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dto.requestDto.BaseReDto;
import com.syni.mdd.yhd.common.all.utils.StringUtils;
import com.syni.mdd.yhd.common.all.validationGroup.GroupDelete;
import com.syni.mdd.yhd.common.all.validationGroup.GroupFind;
import com.syni.mdd.yhd.common.all.validationGroup.GroupInsert;
import com.syni.mdd.yhd.common.all.validationGroup.GroupUpdate;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;

/**
 * @className DxGroupBuyReDto
 * @description TOO
 * @Author cfx
 * @DATE 2019/7/25 10:14
 * @VERSION 1.0
 **/
@Data
public class DxGroupBuyReDto extends BaseReDto{

    @NotNull(groups = {GroupFind.class,GroupInsert.class, GroupUpdate.class, GroupDelete.class})
    private Integer businessId;

    private String groupOriginImg;

    //@NotNull(groups = GroupInsert.class)
    private String groupImg;

    private String detailImg;

    @NotNull(groups = GroupInsert.class)
    @Size(max = 20)
    private String groupName;

    //@NotNull(groups = GroupInsert.class)
    private String useNumber;

    private String groupContent;

    private List<GroupContent> groupContentArg;

    private String groupContentArgs;

    //@NotNull(groups = GroupInsert.class)
    private Double groupValue;

    //@NotNull(groups = GroupInsert.class)
    private Double groupPrice;

    private UseTimeArg useTimeArg;

    private String useTimeArgs;

    private Integer useWay;

    private String useTime;

    private Integer noUseDate;

    private Integer isRefundAnyTime;

    private Integer isOverdueRefund;

    private Integer isFreePackage;

    private Integer isUseTheRoom;

    private Integer isEnjoyOtherBen;

    private Integer needAppointment;

    private Integer limitBuyNum;

    private Integer limitOnceUse;

    private String ortherServices;

    private ExpireTimeArg expireTimeArg;

    private String expireTimeArgs;

    private Date expireTime;

    private String expireMonth;

    private Integer limitSellNum;

    @NotNull(groups = GroupFind.class)
    private Integer status;

    private Integer action;

    private Integer groupTemplateId = 1;

    private Integer isUseOne = 0;

    private Integer isLadyUse = 0;

    private String remark;

    private String groupPhotos;

    private String groupPhotosSmall;

    public void setUseTimeArgs(String useTimeArgs) {
        this.useTimeArgs = useTimeArgs;
        if(StringUtils.isNotBlank(useTimeArgs)) {
            this.useTimeArg = JSON.parseObject(useTimeArgs, UseTimeArg.class);
        }
    }

    public void setGroupContentArgs(String groupContentArgs) {
        this.groupContentArgs = groupContentArgs;
        if(StringUtils.isNotBlank(groupContentArgs)) {
            this.groupContentArg = JSON.parseObject(groupContentArgs, List.class);
        }
    }

    public void setExpireTimeArgs(String expireTimeArgs) {
        this.expireTimeArgs = expireTimeArgs;
        if(StringUtils.isNotBlank(expireTimeArgs)) {
            this.expireTimeArg = JSON.parseObject(expireTimeArgs, ExpireTimeArg.class);
        }
    }

    public void setGroupPhotos(String groupPhotos) {
        this.groupPhotos = groupPhotos;
        if(StringUtils.isNotBlank(groupPhotos)){
            List<String> groupPhotosArray = JSON.parseArray(groupPhotos,String.class);
            if(groupPhotosArray != null && groupPhotosArray.size() > 0) {
                this.groupImg = groupPhotosArray.get(0);
            }
        }
    }


    public void setLimitBuyNum(Integer limitBuyNum) {
        if(limitBuyNum != null && limitBuyNum > 0) {
            this.limitBuyNum = limitBuyNum;
        }
    }

    public void setLimitOnceUse(Integer limitOnceUse) {
        if(limitOnceUse!= null && limitOnceUse > 0) {
            this.limitOnceUse = limitOnceUse;
        }
    }

    public void setNeedAppointment(Integer needAppointment) {
        if(needAppointment != null && needAppointment > 0) {
            this.needAppointment = needAppointment;
        }
    }
}
